/**
 * Created by xuchaosheng on 16/8/5.
 */
main.controller('accountManagerCtrl', ["$scope", "$rootScope", "$location", "tools", "$timeout", function ($scope, $rootScope, $location, tools, $timeout) {
    $scope.newAccountName = '';
    $scope.newAccountPwd = '';
    $scope.newAccountPwdMd5 = '';
    $scope.errInfo = "";

    $scope.createNewAccount = function () {
        if (!$scope.newAccountName || !$scope.newAccountPwd) {
            $scope.errInfo = "用户名和密码都不能为空哦!";
            $timeout(function () {
                $scope.errInfo = "";
            }, 4000);
            return;
        }

        $scope.newAccountPwdMd5 = hex_md5($scope.newAccountPwd);

        tools.get({
            url: '/Ibm-Client/regist.htm',
            data: {
                userName: $scope.newAccountName,
                password: $scope.newAccountPwdMd5
            },
            succ: function (resp) {
                if (resp.success) {
                    tools.msg('成功创建一个名为' + $scope.newAccountName + '的新用户');
                    $scope.reset();
                }
            }
        });
    }

    $scope.reset = function () {
        $scope.newAccountName = '';
        $scope.newAccountPwd = '';
        $scope.errInfo = "";
    }
}]);